package com.ninetaildemonfox.zdl.socialproject.mvp.presenter;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;

import com.google.gson.JsonObject;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.ninetaildemonfox.zdl.socialproject.config.Constants;
import com.ninetaildemonfox.zdl.socialproject.http.https.Model;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.SystemNewsContract;

import java.util.ArrayList;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/8/7
 * 功能描述：
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class SystemNewsPresenter {
    public SystemNewsContract contract;
    public AppCompatActivity me;

    public SystemNewsPresenter(SystemNewsContract contract) {
        this.contract = contract;
    }

    public SystemNewsPresenter(SystemNewsContract contract, AppCompatActivity me) {
        this.contract = contract;
        this.me = me;
    }

    public void getMsgList(String token, String type){
        contract.showLoading();
        Model.getInstance().getUserApi().getMsgList(token,type)
                .enqueue(new Callback<JsonObject>() {
                    @Override
                    public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                        Map<String, String> map = Constants.codeGet(me, response);
                        if (map == null){
                            return;
                        }
                        ArrayList<Map<String, String>> list = JSONUtils.parseKeyAndValueToMapList(map.get("data"));
                        contract.Success(list);
                    }

                    @Override
                    public void onFailure(Call<JsonObject> call, Throwable t) {

                    }
                });
    }

}
